package com.zlzxm.sorting.util.toast;

import android.app.Activity;

import com.hjq.xtoast.XToast;
import com.zlzxm.sorting.R;


/**
 * CREATE BY zlzxm ON 2022/7/27
 */
public class XToastUtil {

    public static final int NORMAL = 0;
    public static final int ERROR = 1;


    public static XMsg  createErrorMsg(String msg){

        XMsg xMsg = new XMsg();
        xMsg.type = ERROR;
        xMsg.msg = msg;
        return xMsg;
    }

    public static XMsg  createNormalMsg(String msg){

        XMsg xMsg = new XMsg();
        xMsg.type = NORMAL;
        xMsg.msg = msg;
        return xMsg;
    }

    public static class XMsg{

        private int type;

        private String msg;

        public int getType() {
            return type;
        }

        public void setType(int type) {
            this.type = type;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }

    public static void showXMsg(Activity context,XMsg xMsg){

        switch (xMsg.type){

            case XToastUtil.ERROR:
                showErrorToast(context,xMsg.msg);
                break;

            default:
                showNormalMsgToast(context,xMsg.msg);
                break;
        }


    }


    public static void showErrorToast(Activity context, String error){

        new XToast(context)
                .setContentView(R.layout.layout_toast)
                .setDuration(2000)
                .setImageDrawable(android.R.id.icon, R.drawable.ic_error)
                .setText(android.R.id.message, error)
                .show();
    }

    public static void showNormalMsgToast(Activity context, String msg){

        new XToast(context)
                .setContentView(R.layout.layout_toast)
                .setDuration(2000)
                .setImageDrawable(android.R.id.icon, R.drawable.ic_msg)
                .setText(android.R.id.message, msg)
                .show();
    }

}
